home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / gfx / pbm / netpbm1.lha / netpbm / pbmplus.h < prev    next >
C/C++ Source or Header  |  1993-12-07  |  9KB  |  274 lines

  1. /* pbmplus.h - header file for PBM, PGM, PPM, and PNM
  2. **
  3. ** Copyright (C) 1988, 1989, 1991 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #ifndef _PBMPLUS_H_
  14. #define _PBMPLUS_H_
  15.  
  16. #include <sys/types.h>
  17. #include <ctype.h>
  18. #include <stdio.h>
  19. #ifdef VMS
  20. #include <perror.h>
  21. #include <errno.h>
  22. #endif
  23.  
  24. #if defined(USG) || defined(SVR4) || defined(VMS)
  25. #define SYSV
  26. #endif
  27. #if ! ( defined(BSD) || defined(SYSV) || defined(MSDOS) || defined(AMIGA) )
  28. /* CONFIGURE: If your system is >= 4.2BSD, set the BSD option; if you're a
  29. ** System V site, set the SYSV option; if you're IBM-compatible, set MSDOS;
  30. ** and if you run on an Amiga, set AMIGA. If your compiler is ANSI C, you're
  31. ** probably better off setting SYSV - all it affects is string handling.
  32. */
  33. #define BSD
  34. /* #define SYSV */
  35. /* #define MSDOS */
  36. /* #define AMIGA */
  37. #endif
  38.  
  39. /* CONFIGURE: If you have an X11-style rgb color names file, define its
  40. ** path here.  This is used by PPM to parse color names into rgb values.
  41. ** If you don't have such a file, comment this out and use the alternative
  42. ** hex and decimal forms to specify colors (see ppm/pgmtoppm.1 for details).
  43. #define RGB_DB "/usr/lib/X11/rgb"
  44. /*#define RGB_DB "/usr/openwin/lib/rgb.txt"*/
  45. #ifdef VMS
  46. #define RGB_DB "PBMplus_Dir:RGB.TXT"
  47. #endif
  48.  
  49. /* CONFIGURE: If you want to enable writing "raw" files, set this option.
  50. ** "Raw" files are smaller, and much faster to read and write, but you
  51. ** must have a filesystem that allows all 256 ASCII characters to be read
  52. ** and written.  You will no longer be able to mail P?M files without 
  53. ** using uuencode or the equivalent, or running the files through pnmnoraw.
  54. ** Note that reading "raw" files works whether writing is enabled or not.
  55. */
  56. #define PBMPLUS_RAWBITS
  57.  
  58. /* CONFIGURE: PGM can store gray values as either bytes or shorts.  For most
  59. ** applications, bytes will be big enough, and the memory savings can be
  60. ** substantial.  However, if you need more than 8 bits of grayscale resolution,
  61. ** then define this symbol. Unless your computer is very slow or you are short
  62. ** of memory, there is no reason why you should not set this symbol.
  63. */
  64. #define PGM_BIGGRAYS
  65.  
  66. /* CONFIGURE: Normally, PPM handles a pixel as a struct of three grays.
  67. ** If grays are stored in bytes, that's 24 bits per color pixel; if
  68. ** grays are stored as shorts, that's 48 bits per color pixel.  PPM
  69. ** can also be configured to pack the three grays into a single longword,
  70. ** 10 bits each, 30 bits per pixel.
  71. **
  72. ** If you have configured PGM with the PGM_BIGGRAYS option, AND you don't
  73. ** need more than 10 bits for each color component, AND you care more about
  74. ** memory use than speed, then this option might be a win.  Under these
  75. ** circumstances it will make some of the programs use 1.5 times less space,
  76. ** but all of the programs will run about 1.4 times slower.
  77. **
  78. ** If you are not using PGM_BIGGRAYS, then this option is useless -- it
  79. ** doesn't save any space, but it still slows things down.
  80. */
  81. /* #define PPM_PACKCOLORS */
  82.  
  83. /* CONFIGURE: uncomment this to enable debugging checks. */
  84. /* #define DEBUG */
  85.  
  86.  
  87. #if ( defined(SYSV) || defined(AMIGA) )
  88.  
  89. #include <string.h>
  90. #define index(s,c) strchr(s,c)
  91. #define rindex(s,c) strrchr(s,c)
  92. #define srandom(s) srand(s)
  93. #define random rand
  94. #ifndef _DCC    /* Amiga DICE Compiler */
  95. #define bzero(dst,len) memset(dst,0,len)
  96. #define bcopy(src,dst,len) memcpy(dst,src,len)
  97. #define bcmp memcmp
  98. extern void srand();
  99. extern int rand();
  100. #endif /* _DCC */
  101.  
  102. #else /* SYSV or AMIGA */
  103.  
  104. #include <strings.h>
  105. extern void srandom();
  106. extern long random();
  107.  
  108. #endif /*SYSV or AMIGA*/
  109.  
  110. #ifdef AMIGA
  111. #include <fcntl.h>
  112. #include <time.h>
  113. #include <stdlib.h>
  114. #else
  115. extern int atoi();
  116. extern void exit();
  117. extern long time();
  118. extern int write();
  119. #endif
  120.  
  121. /* CONFIGURE: On most BSD systems, malloc() gets declared in stdlib.h, on
  122. ** system V, it gets declared in malloc.h. On some systems, malloc.h
  123. ** doesn't declare these, so we have to do it here. On other systems,
  124. ** for example HP/UX, it declares them incompatibly.  And some systems,
  125. ** for example Dynix, don't have a malloc.h at all.  A sad situation.
  126. ** If you have compilation problems that point here, feel free to tweak
  127. ** or remove these declarations.
  128. */
  129. #ifdef BSD
  130. #include <stdlib.h>
  131. #endif
  132. #if (defined(SYSV) && !defined(VMS))
  133. #include <malloc.h>
  134. #endif
  135. /* extern char* malloc(); */
  136. /* extern char* realloc(); */
  137. /* extern char* calloc(); */
  138.  
  139. /* CONFIGURE: Some systems don't have vfprintf(), which we need for the
  140. ** error-reporting routines.  If you compile and get a link error about
  141. ** this routine, uncomment the first define, which gives you a vfprintf
  142. ** that uses the theoretically non-portable but fairly common routine
  143. ** _doprnt().  If you then get a link error about _doprnt, or
  144. ** message-printing doesn't look like it's working, try the second
  145. ** define instead.
  146. */
  147. /* #define NEED_VFPRINTF1 */
  148. /* #define NEED_VFPRINTF2 */
  149.  
  150. /* CONFIGURE: Some systems don't have strstr(), which some routines need.
  151. ** If you compile and get a link error about this routine, uncomment the
  152. ** define, which gives you a strstr.
  153. */
  154. /* #define NEED_STRSTR */
  155.  
  156. /* CONFIGURE: If you don't want a fixed path to an X11 color name file
  157. ** compiled into PBMPlus, set this option.  Now RGB_DB (see Makefile)
  158. ** defines the name of an environment-variable that holds the complete
  159. ** path and name of this file.
  160. */
  161. /* #define A_RGBENV */
  162.  
  163. /* CONFIGURE: Set this option if your compiler uses strerror(errno)
  164. ** instead of sys_errlist[errno] for error messages.
  165. */
  166. /* #define A_STRERROR */
  167.  
  168. /* CONFIGURE: On small systems without VM it is possible that there is
  169. ** enough memory for a large array, but it is fragmented.  So the usual
  170. ** malloc( all-in-one-big-chunk ) fails.  With this option, if the first
  171. ** method fails, pm_allocarray() tries to allocate the array row by row.
  172. */
  173. /* #define A_FRAGARRAY */
  174.  
  175. /*
  176. ** Some special things for the Amiga.
  177. */
  178.  
  179. /* End of configurable definitions. */
  180.  
  181.  
  182. #ifdef AMIGA
  183. #include <clib/exec_protos.h>
  184. #define getpid(x)   ((long)FindTask(NULL))
  185. #ifdef _DCC /* Amiga DICE Compiler, dynamic stack variables */
  186. long _stack_fudge = 16384;
  187. long _stack_chunk = 32768;
  188. #endif /* _DCC */
  189. #endif /* AMIGA */
  190.  
  191.  
  192. #undef max
  193. #define max(a,b) ((a) > (b) ? (a) : (b))
  194. #undef min
  195. #define min(a,b) ((a) < (b) ? (a) : (b))
  196. #undef abs
  197. #define abs(a) ((a) >= 0 ? (a) : -(a))
  198. #undef odd
  199. #define odd(n) ((n) & 1)
  200.  
  201.  
  202. /* Definitions to make PBMPLUS work with either ANSI C or C Classic. */
  203.  
  204. #if __STDC__
  205. #define ARGS(alist) alist
  206. #else /*__STDC__*/
  207. #define ARGS(alist) ()
  208. #define const
  209. #endif /*__STDC__*/
  210.  
  211.  
  212. /* Initialization. */
  213.  
  214. void pm_init ARGS(( int* argcP, char* argv[] ));
  215.  
  216. /* Variable-sized arrays definitions. */
  217.  
  218. char** pm_allocarray ARGS(( int cols, int rows, int size ));
  219. char* pm_allocrow ARGS(( int cols, int size ));
  220. void pm_freearray ARGS(( char** its, int rows ));
  221. void pm_freerow ARGS(( char* itrow ));
  222.  
  223.  
  224. /* Case-insensitive keyword matcher. */
  225.  
  226. int pm_keymatch ARGS(( char* str, char* keyword, int minchars ));
  227.  
  228.  
  229. /* Log base two hacks. */
  230.  
  231. int pm_maxvaltobits ARGS(( int maxval ));
  232. int pm_bitstomaxval ARGS(( int bits ));
  233.  
  234.  
  235. /* Error handling definitions. */
  236.  
  237. void pm_message ARGS(( char*, ... ));
  238. void pm_error ARGS(( char*, ... ));            /* doesn't return */
  239. void pm_perror ARGS(( char* reason ));            /* doesn't return */
  240. void pm_usage ARGS(( char* usage ));            /* doesn't return */
  241.  
  242.  
  243. /* File open/close that handles "-" as stdin and checks errors. */
  244.  
  245. FILE* pm_openr ARGS(( char* name ));
  246. FILE* pm_openw ARGS(( char* name ));
  247. void pm_close ARGS(( FILE* f ));
  248.  
  249.  
  250. /* Endian I/O. */
  251.  
  252. int pm_readbigshort ARGS(( FILE* in, short* sP ));
  253. int pm_writebigshort ARGS(( FILE* out, short s ));
  254. int pm_readbiglong ARGS(( FILE* in, long* lP ));
  255. int pm_writebiglong ARGS(( FILE* out, long l ));
  256. int pm_readlittleshort ARGS(( FILE* in, short* sP ));
  257. int pm_writelittleshort ARGS(( FILE* out, short s ));
  258. int pm_readlittlelong ARGS(( FILE* in, long* lP ));
  259. int pm_writelittlelong ARGS(( FILE* out, long l ));
  260.  
  261.  
  262. /* Compatibility stuff */
  263.  
  264. #ifdef NEED_STRSTR
  265. char *strstr ARGS((char *s1, char *s2));
  266. #endif
  267.  
  268. #if defined(NEED_VFPRINTF1) || defined(NEED_VFPRINTF2)
  269. int vfprintf ARGS(( FILE* stream, char* format, va_list args ));
  270. #endif /*NEED_VFPRINTF*/
  271.  
  272.  
  273. #endif /*_PBMPLUS_H_*/
  274.